package com.superteam.mac.util;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class SendPost {

	public void sendReq() {
		String url = "http://localhost:8089/macmanage/MachineData";
		//String url = "file://D:/aa.txt";
		URL dataUrl;		
		try {
			
			dataUrl = new URL(url);
			HttpURLConnection con = (HttpURLConnection) dataUrl.openConnection();
			con.setRequestMethod("POST");
			con.setRequestProperty("Proxy-Connection", "Keep-Alive");
			
			con.setDoOutput(true);
			con.setDoInput(true);
			StringBuffer sb = new StringBuffer();
			sb.append("data=");
			/*for (int i = 0; i < 2; i++) {
				sb.append("modeName_"+i+",modeCode_"+i+",modeStaut,1,"+Math.random()+",测试|");
			}*/
			sb.append("车间1,0101,主轴转速,2011-4-4 19:12:29,14|车间1,0104,主轴转速,2011-4-3 19:11:29,6|车间1,0101,主轴负荷,2011-4-3 19:11:29,8|车间1,0101,进给,2011-4-3 19:11:29,11|车间1,0101,主轴转速,2011-4-3 19:11:30,11|车间1,0104,主轴转速,2011-4-3 19:11:30,6|车间1,0101,主轴负荷,2011-4-3 19:11:30,8|车间1,0102,主轴转速,2011-4-3 19:11:30,9|车间1,0101,进给,2011-4-3 19:11:30,11|车间1,0104,主轴转速,2011-4-3 19:11:31,6|车间1,0101,主轴转速,2011-4-3 19:11:31,11|车间1,0102,主轴转速,2011-4-3 19:11:31,9|车间1,0101,主轴负荷,2011-4-3 19:11:31,8|车间1,0103,主轴转速,2011-4-3 19:11:31,0|车间1,0101,进给,2011-4-3 19:11:31,11|车间1,0104,主轴转速,2011-4-3 19:11:32,6|车间1,0101,主轴转速,2011-4-3 19:11:32,11|车间1,0101,主轴负荷,2011-4-3 19:11:32,8|车间1,0103,主轴转速,2011-4-3 19:11:32,0|车间1,0102,主轴转速,2011-4-3 19:11:32,9|车间1,0101,进给,2011-4-3 19:11:32,11|车间1,0104,主轴转速,2011-4-3 19:11:33,6|车间1,0101,主轴转速,2011-4-3 19:11:33,11|车间1,0102,主轴转速,2011-4-3 19:11:33,9|车间1,0103,主轴转速,2011-4-3 19:11:33,0|车间1,0101,主轴负荷,2011-4-3 19:11:33,8|车间1,0101,进给,2011-4-3 19:11:33,11|车间1,0104,主轴转速,2011-4-3 19:11:34,7|车间1,0101,主轴转速,2011-4-3 19:11:34,11|车间1,0103,主轴转速,2011-4-3 19:11:34,0|车间1,0102,主轴转速,2011-4-3 19:11:34,9|车间1,0101,主轴负荷,2011-4-3 19:11:34,8|车间1,0101,进给,2011-4-3 19:11:34,11|车间1,0104,主轴转速,2011-4-3 19:11:35,7|车间1,0101,主轴转速,2011-4-3 19:11:25,15|车间1,0101,主轴负荷,2011-4-3 19:11:35,8|车间1,0103,主轴转速,2011-4-3 19:11:35,0|车间1,0102,主轴转速,2011-4-3 19:11:35,9|");

			String postData = sb.toString();
			
			System.out.println(postData);
			//System.out.println(postData.length());
			OutputStream os = con.getOutputStream();
			DataOutputStream dos = new DataOutputStream(os);
			dos.write(postData.getBytes());
			dos.flush();
			dos.close();

			InputStream is = con.getInputStream();
			DataInputStream dis = new DataInputStream(is);
			byte d[] = new byte[dis.available()];
			dis.read(d);
			con.disconnect();

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			for (int i = 0; i < 1; i++) {
				new SendPost().sendReq();
				Thread.sleep(1000);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
